﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.IO;
using System.IO.Compression;

namespace CNTVNow.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            //routes.Clear();
            // Turns off the unnecessary file exists check
            //routes.RouteExistingFiles = true;

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Ignore text, html, files.
            /*
            routes.IgnoreRoute("{file}.txt");
            routes.IgnoreRoute("{file}.htm");
            routes.IgnoreRoute("{file}.html");
            routes.IgnoreRoute("{file}.css");
            routes.IgnoreRoute("{file}.js");
            routes.IgnoreRoute("{file}.ashx");
            routes.IgnoreRoute("{file}.aspx");
             */
            // Ignore the assets directory which contains images, js, css & html
            //routes.IgnoreRoute("Content/{*pathInfo}");
            //routes.IgnoreRoute("Scripts/{*pathInfo}");
            // Ignore the error directory which contains error pages
            //routes.IgnoreRoute("ErrorPages/{*pathInfo}");
            // Exclude favicon (google toolbar request gif file as fav icon which is weird)
            //routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" });


            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //HttpApplication app = (HttpApplication)sender;
            //string acceptEncoding = app.Request.Headers["Accept-Encoding"];
            //Stream prevUncompressedStream = app.Response.Filter;
            //if (acceptEncoding == null || acceptEncoding.Length == 0)
            //    return;
            //acceptEncoding = acceptEncoding.ToLower();
            //if (acceptEncoding.Contains("gzip"))
            //{
            //    // gzip
            //    app.Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
            //    app.Response.AppendHeader("Content-Encoding", "gzip");
            //}
            //else if (acceptEncoding.Contains("deflate"))
            //{
            //    // defalte
            //    app.Response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress);
            //    app.Response.AppendHeader("Content-Encoding", "deflate");
            //}
        }
    }
}